package com.cxl;

import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.sun.mail.util.MailSSLSocketFactory;

import java.security.GeneralSecurityException;

/**
 * @author: 20971
 * @time: 2022/3/10 16:34
 * @description:
 */

public class EmailApplication {


    public static void main(String[] args) throws GeneralSecurityException {
        //账号
 /*       MailAccount mailAccount = new MailAccount();
        mailAccount.setFrom("2097113175@qq.com");
        mailAccount.setPass("qstzwdducyjubajd");
        mailAccount.setHost("smtp.qq.com");
        mailAccount.setPort(465);
        mailAccount.setUser("2097113175");
        mailAccount.setSslEnable(true);
        mailAccount.setAuth(true);*/
/*
        // 报错 :Could not connect to SMTP host: smtp.qq.com, port: 465
        // 原因：需要SSL验证造成的，我们可以手动跳过这个验证，加入以下代码
        MailSSLSocketFactory sf = new MailSSLSocketFactory();
        sf.setTrustAllHosts(true);
        mailAccount.setCustomProperty("mail.smtp.ssl.socketFactory", sf);*/

        //创MilUtil工具
        System.out.println("发送前");
        MailUtil.send("2097113175@qq.com", "邮箱主题", "邮箱内容", false);
        System.out.println("发送成功");
    }
}
